<?php

class AttrFormModel extends Model{
	public $table = 'attr_class';
	public function attrForm($gtid){
		$attrData = $this->where(array('gt_id'=>$gtid,'is_spec'=>0))->all();
		if(!empty($data)){
			$attrData = $data;
		}
		if(!empty($attrData)){
			foreach ($attrData as $n => $attrd) {
				$function = $attrd['show_type'];
				
				$attrValueData = $this->$function($attrd['ac_id']);
				$attrData[$n]['html'] = $attrValueData;
			}
		}
		
		return $attrData;
	}

	public function dropdown($acid){
		$attrValue = M('attr_value')->where(array('ac_id'=>$acid))->all();
		$html = "<select name='attr[{$acid}]'>";
		foreach ($attrValue as $n => $v) {
			
			$html.="<option value='".$v['av_id']."|".$v['attr_value']."'>".$v['attr_value']."</option>";
		}
		$html.= "</select>";
		return $html;
	}
	public function text($acid){

		$attrValue = M('attr_value')->where(array('ac_id'=>$acid))->all();
		$name = $acid."|".$attrValue[0]['av_id'];
		$html = "<input type='text' name='attr[{$name}]' value='".$attrValue[0]['attr_value']."'/>";
		return $html;
	}

}
?>
